Convert-XY: type-safe interchange of C++ and Python containers for NumPy extensions
نویسنده
چکیده
At compile time, pattern matching is applied to the structure of the C++ type of y. This yields two pieces of information: how to check for compatible structure in the Python type (e.g. a dictionary mapping strings to lists, tuples, arrays or sequences is compatible with map>) and which set of converters is applicable (e.g. sequences vs. dictionaries). Dynamic type checkers and converter functions can be built with this static type information at compile time. Further, the library statically determines when an array buffer pointer can be reused, preventing unnecessary copying which can be very useful for programs operating on large data sets. LIBCVD, a popular computer vision library used in our work, provides a BasicImage class, which can be used to wrap two-dimensional image addressing around a buffer pointer. Convert-XY avoids copying and allocation by reusing the NumPy buffer pointer whenever it can: void example(PyObject *x) { map > y; convert(x, y); }
منابع مشابه
unPython: Converting Python Numerical Programs into C
unPython is a Python-to-C compiler intended for numerical Python programs. The compiler takes as input type-annotated Python source and produces C source code for an equivalent extension module. The compiler is NumPy-aware and can convert most NumPy indexing or slicing operations into C array accesses. Furthermore the compiler also allows annotating certain for-loops as parallel and can generat...
متن کاملJyNI - Using native CPython-Extensions in Jython
Jython is a Java based Python implementation and the most seamless way to integrate Python and Java. However, it does not support native extensions written for CPython like NumPy or SciPy. Since most scientific Python code fundamentally depends on exactly such native extensions directly or indirectly, it usually cannot be run with Jython. JyNI (Jython Native Interface) aims to close this gap. I...
متن کاملFormula translation in Blitz++, NumPy and modern Fortran: A case study of the language choice tradeoffs
Three object-oriented implementations of a prototype solver of the advection equation are introduced. The presented programs are based on Blitz++ (C++), NumPy (Python), and Fortran’s built-in array containers. The solvers include an implementation of the Multidimensional Positive-Definite Advective Transport Algorithm (MPDATA). The introduced codes exemplify how the application of object-orient...
متن کاملGarbage Collection in JyNI - How to bridge Mark/Sweep and Reference Counting GC
Jython is a Java-based Python implementation and the most seamless way to integrate Python and Java. It achieves high efficiency by compiling Python code to Java bytecode and thus letting Java’s JIT optimize it – an approach that enables Python code to call Java functions or to subclass Java classes. It enables Python code to leverage Java’s multithreading features and utilizes Java’s built-in ...
متن کاملPyFAI: a Python library for high performance azimuthal integration on GPU
The pyFAI package has been designed to reduce X-ray diffraction images into powder diffraction curves to be further processed by scientists. This contribution describes how to convert an image into a radial profile using the Numpy package, how the process was accelerated using Cython. The algorithm was parallelised, needing a complete re-design to benefit from massively parallel devices like gr...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2009